package com.globaleducation365.cartoonv1.customize;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;

import com.globaleducation365.cartoonv1.adapter.VideoIndexFragmentAdapter;

public class CustomHorizontal extends HorizontalScrollView {
	boolean expanded = true;

	public CustomHorizontal(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);

	}

	public CustomHorizontal(Context context, AttributeSet attrs) {
		super(context, attrs);

	}

	public CustomHorizontal(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public boolean isExpanded() {
		return expanded;
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		if (isExpanded()) {
			int expandSpec = MeasureSpec.makeMeasureSpec(
					Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
			super.onMeasure(widthMeasureSpec, expandSpec);
			ViewGroup.LayoutParams params = getLayoutParams();
			params.height = getMeasuredHeight();
		} else {
			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		}
	}

	public void setExpanded(boolean expanded) {
		this.expanded = expanded;
	}

	public void setAdapter(VideoIndexFragmentAdapter adapterVideo) {
		if (getChildCount() == 0) {

		}
		if (getChildCount() == 0 || adapterVideo == null)
			return;

		ViewGroup parent = (ViewGroup) getChildAt(0);

		parent.removeAllViews();

		for (int i = 0; i < adapterVideo.getCount(); i++) {
			parent.addView(adapterVideo.getView(i, null, parent));
		}

	}
}
